<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;

class Filelist extends Model
{
    use Notifiable;
    use SoftDeletes;
    /**
     * 需要转换成日期的属性
     *
     * @var array
     */
    protected $dates = ['deleted_at'];

    protected $table = 'filelists';

    // 列表
    public static function getList($request)
    {
        $query = self::select('*');
        if (isset($request->sort) && $request->sort) {
            $query->orderBy($request->sort, $request->order);
        } 
        $query->orderBy('id', 'desc');
        $res = $query->paginate($request->size);
        return $res ? $res->toArray() : [];
    }

    // 详情
    public static function getInfo($id)
    {
        $res = self::select('*')->where('id', $id)->first();
        return $res ? $res->toArray() : [];
    }

    // 删除
    public static function del($id)
    {
        $res = static::where('id', $id)->delete();
        return $res;
    }
}
